
import { serviceConfig } from "@Tea/model";
import express, { Request, Response } from "express"
import { Token } from "../../dao/Token";
import { SystemContext } from "../../context/SystemContext";
import { LoggedInRequest } from "../../types";
import { MenuContext } from "../../context/MenuContext";

const commonRouter = express.Router()

// 获取菜单
commonRouter.get("/menu", async (req: LoggedInRequest, res: Response) => {
  setTimeout(async () => {
    res.send({
      code: 1,
      data: await MenuContext.getInstance().getUserMenu(req.userInfo.userId)
    })
  }, 1250)
})

// 获取用户
commonRouter.get("/userList", async (req: Request, res: Response) => {
  setTimeout(async () => {
    res.send({
      code: 1,
      data: await SystemContext.getInstance().getUserList()
    })
  }, 1250)
})

// 获取系统信息
commonRouter.get("/getSystemIfon", async (req: Request, res: Response) => { 
  setTimeout(async () => {
    res.send({
      code: 1,
      data: await SystemContext.getInstance().getSystemInfo(res)
    })
  }, 1250)
})

// 测试 token
commonRouter.get("/testToken", async (req: Request, res: Response) => {
  const token = Token.getInstance()
  console.log(token);
  
  res.send({
    code: 1,
    data:34
  })
})

// 文件上传
/* commonRouter.post('/upload', async (req: Request, res: Response)=>{
  try {
    const urlName =  await upload(req)
    res.send({
      code: 1,
      msg: "上传成功！", 
      data: urlName
    })
  } catch (e) {
    res.send({
      code: 0,
      msg:"失败了"
    })
  }
}) */

export default commonRouter